// 专门负责用户相关的请求

import request from '@/service'
export const getUserList = params => {
  return request({
    method: 'GET',
    url: 'users',
    // 通过
    params
  })
}
export const updateUserStatus = userinfo => {
  return request({
    method: 'put',
    url: `users/${userinfo.id}/state/${userinfo.mg_state}`
  })
}
// 添加用户
export const addUser = data => {
  return request({
    method: 'post',
    url: 'users',
    data
  })
}
// 编辑功能更新
export const getUserDetail = id => {
  return request({
    method: 'GET',
    url: `users/${id}`
  })
}

/**
 * 确认编辑用户
 */

export const editUser = ({ id, email, mobile }) => {
  return request({
    method: 'put',
    url: `users/${id}`,
    data: {
      email,
      mobile
    }
  })
}

/**
 * 删除用户
 */

export const removeUser = id => {
  return request({
    method: 'delete',
    url: `users/${id}`
  })
}

/**
 * 分配角色
 */

export const assignRolesList = () => {
  return request({
    method: 'get',
    url: 'roles'
  })
}

/**
 * 分配用户角色
 */

export const assignUser = (id, rid) => {
  return request({
    method: 'put',
    url: `users/${id}/role`,
    data: {
      rid
    }
  })
}
